<div class="fm-content">
  <!-- 最上面标题栏 -->
  <div class="title">
    <i nz-icon [type]="'desktop'"></i>
    &nbsp;&nbsp;应用系统注册
  </div>
  <!-- 内容 -->
  <div class="work">

    <!-- 查询框 -->
    <div class="top">
      <input nz-input placeholder="名称" class="fm-input first-input" [(ngModel)]="fs.queryObject['display:like']" />
      <input nz-input placeholder="标识" class="fm-input" [(ngModel)]="fs.queryObject['id:like']" />
      <nz-button-group>
        <button nz-button nzType="primary" (click)="fs.loadData(true)">查询</button>
        <button nz-button (click)="fs.resetQueryObject() && fs.loadData(true)">重置</button>
      </nz-button-group>
      <div class="tool-right">
        <nz-button-group>
          <button nz-button [nzType]="'primary'" (click)="fs.addRow()">新增</button>
          <button nz-button (click)="fs.editRow()">编辑</button>
          <button nz-popconfirm nzTitle="确认删除选择项?" (nzOnConfirm)="fs.delEntitys()" nzPlacement="bottomRight"
            nz-button>删除</button>
        </nz-button-group>
      </div>
    </div>

    <!-- 右则样表单主体 -->
    <div class="work-content">
      <div class="table">
        <nz-table nzSize="middle" nzShowSizeChanger [nzPageSizeOptions]='[ 10, 15, 20, 30, 40, 50 ]'
          [nzFrontPagination]="false" [nzData]="fs.datas" [nzLoading]="fs.isLoading || fs.isDeleing"
          [nzTotal]="fs.rowsCount" [(nzPageIndex)]="fs.pageIndex" [(nzPageSize)]="fs.pageSize"
          (nzPageIndexChange)="fs.loadData()" (nzPageSizeChange)="fs.loadData(true)">
          <thead (nzSortChange)="fs.sort($event)" nzSingleSort>
            <tr>
              <th nzWidth="5%" nzShowCheckbox [(nzChecked)]="fs.allChecked" [nzIndeterminate]="fs.indeterminate"
                (nzCheckedChange)="fs.checkAll($event)"></th>
              <th nzWidth="30%">名称/标识</th>
              <th nzWidth="15%">类型</th>
              <th nzWidth="30%">授权码</th>
              <th nzWidth="20%">操作</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of fs.datas">
              <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="fs.refreshCheckStatus()">
              </td>
              <td><span (click)="fs.editRow(data)"
                  class="form-edit">{{data.display}}<br />{{data.url}}</span>
              </td>
              <td>
                {{data.typeName}}<br />
                {{data.valid==true?'有效':'无效'}}
              </td>
              <td>
                SSO:{{data.ssoid}}<br />
                AppKey:{{data.id}}<br />
                AppSecret:{{data.ifprovide}}
              </td>
              <td>
                <a nz-popconfirm nzTitle="确认授权吗?" (nzOnConfirm)="editSSO(data)" nzPlacement="bottomRight"
                  class="form-button">单点登录授权</a><br />
                <a class="form-button" (click)="editInterface(data)">接口访问授权</a>
              </td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>

    <nz-modal nzWidth='830' nzTitle="编辑" [nzMaskClosable]='false' [nzFooter]="null" [(nzVisible)]="fs.isEditVisible"
      (nzOnCancel)="fs.closeEdit()">
      <form nz-form [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">标识</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="id.invalid?'error':'success'" nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.id" id="id" name="id" #id="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">名称</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="display.invalid?'error':'success'"
                nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.display" id="display" name="display" #display="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">地址</nz-form-label>
              <nz-form-control class="form-control3" [nzValidateStatus]="url.invalid?'error':'success'" nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.url" name="url" #url="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">类型</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="type.invalid?'error':'success'" nzHasFeedback>
                <nz-select [(ngModel)]="fs.er.type" (nzOpenChange)="serTypeDic.load('0')" name="type" required
                  #type="ngModel" [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of serTypeDic.datas" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="serTypeDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                  <span *ngIf="!serTypeDic.isLoaded">
                    <nz-option [nzLabel]="fs.er.typeName" [nzValue]="fs.er.type">
                    </nz-option>
                  </span>
                </nz-select>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12" [hidden]="fs.er.type !== '3'">
            <nz-form-item>
              <nz-form-label class="form-label">租户</nz-form-label>
              <nz-form-control class="form-control">
                <app-tenantselect [(userNames)]='fs.er.tenantname' [(userIDs)]='fs.er.tenantid'></app-tenantselect>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">Logo</nz-form-label>
              <nz-form-control class="form-control3">
                <nz-upload nzAction="{{ ffs.getUploadUrl() }}" [nzMultiple]="false" [nzShowUploadList]="true"
                  [nzShowButton]="fs.er.syspic ? fs.er.syspic.length < 1 : true" [(nzFileList)]="fs.er.syspic"
                  name="syspic" [nzAccept]="'.svg'" (nzChange)="ffs.handleChange($event)">
                  <button nz-button><i nz-icon type="upload"></i><span>上传</span></button>
                </nz-upload>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">排序</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="order.invalid?'error':'success'" nzHasFeedback>
                <nz-input-number required [(ngModel)]="fs.er.order" name="order" [nzMin]="1" #order="ngModel"
                  [nzMax]="100" [nzStep]="1" class="form-control">
                </nz-input-number>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">有效</nz-form-label>
              <nz-form-control class="form-control">
                <nz-switch nzCheckedChildren="有" nzUnCheckedChildren="无" [(ngModel)]="fs.er.valid" name="valid">
                </nz-switch>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" class="form-button-align">
            <button nz-button nzType="default" (click)="fs.closeEdit()" class="form-button">取消</button>
            <button nz-button nzType="primary"
              [disabled]='id.invalid || url.invalid || display.invalid || order.invalid' (click)="fs.save()"
              [nzLoading]="fs.isSaveing">保存</button>
          </div>
        </div>
      </form>
    </nz-modal>

    <nz-modal nzWidth='360' nzTitle="接口访问授权" [nzMaskClosable]='false' [nzFooter]="null" [(nzVisible)]="interfaceVisible"
      (nzOnCancel)="closeInterface()">
      <form nz-form [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-control>
              <nz-radio-group [(ngModel)]="updateToken" name="updateToken">
                <label nz-radio nzValue="true">更新token</label>
                <label nz-radio nzValue="false">不更新token</label>
              </nz-radio-group>
            </nz-form-control>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" style="height: 400px;overflow: auto;">
            <nz-tree nzAsyncData [nzCheckedKeys]="ifRow.ifpower" 
              (nzCheckBoxChange)="checked($event, ifRow.ifpower)"
              [nzData]="sysDic.treeDatas" nzCheckable [nzCheckStrictly]="true">
            </nz-tree>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" class="form-button-align">
            <button nz-button nzType="default" (click)="closeInterface()" class="form-button">取消</button>
            <button nz-button nzType="primary" (click)="saveInterface()" [nzLoading]="fs.isSaveing">授权</button>
          </div>
        </div>
      </form>
    </nz-modal>
  </div>
</div>
